package com.fengke.cn.yejian11.fragment;
import android.graphics.Color;
import android .support.v4.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fengke.cn.yejian11.R;

public class MainFragment extends Fragment  {
    private TextView yuejian_me_text,yuejian_showpic_text,yuejian_yuejian_text,yuejian_club_text,yuejian_train_text;
    private ImageView yuejian_me_pic,yuejian_showpic_pic,yuejian_yuejian_pic,yuejian_club_pic,yuejian_train_pic;
    private FragmentTransaction transaction;
    private View view;
    private TextView title;
    private FragmentManager fragmentManager;
    private ClubFragment clubFragment;
    private MeFragment meFragment;
    private ShowPicFragment showPicFragment;
    private trainFragment trainF;
    private YuejianFragment yuejianFragment;
    private LinearLayout l_train,l_club,l_yuejian,l_showpic,l_me;

    public MainFragment() {
        // Required empty public constructor
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view=inflater.inflate(R.layout.fragment_main, container, false);

        init();
        transaction=fragmentManager.beginTransaction();
        transaction.add(R.id.mainFrame,yuejianFragment);
        transaction.commit();
        yuejian_yuejian_pic.setImageDrawable(getResources().getDrawable(R.drawable.ic_jianshen_1));
        yuejian_yuejian_text.setTextColor(Color.rgb(6,226,17));
        event_2();
        return view;
    }
    public void event_2()
    {
        l_train.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                replace(trainF);
                setImage();
                setTextColor();
                yuejian_train_pic.setImageDrawable(getResources().getDrawable(R.drawable.ic_train_running));
                yuejian_train_text.setTextColor(Color.rgb(6,226,17));
                title.setText("体育培训");
            }
        });
        l_showpic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                replace(showPicFragment);
                setImage();
                setTextColor();
                yuejian_showpic_pic.setImageDrawable(getResources().getDrawable(R.drawable.ic_icon_pic_1));
                yuejian_showpic_text.setTextColor(Color.rgb(6,226,17));
                title.setText("晒图");
            }
        });
        l_yuejian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                replace(yuejianFragment);
                setImage();
                setTextColor();
                yuejian_yuejian_pic.setImageDrawable(getResources().getDrawable(R.drawable.ic_jianshen_1));
                yuejian_yuejian_text.setTextColor(Color.rgb(6,226,17));
                title.setText("约见体育联盟");
            }
        });
        l_me.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                replace(meFragment);
                setImage();
                setTextColor();
                yuejian_me_pic.setImageDrawable(getResources().getDrawable(R.drawable.ic_me_1));
                yuejian_me_text.setTextColor(Color.rgb(6,226,17));
                title.setText("我的");
            }
        });
        l_club.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                replace(clubFragment);
                setImage();
                setTextColor();
                yuejian_club_pic.setImageDrawable(getResources().getDrawable(R.drawable.ic_club_1));
                yuejian_club_text.setTextColor(Color.rgb(6,226,17));
                title.setText("俱乐部");
            }
        });
    }
    public void init()
    {
        fragmentManager=this.getChildFragmentManager();
        meFragment=new MeFragment();
        trainF=new trainFragment();
        showPicFragment=new ShowPicFragment();
        title=(TextView)view.findViewById(R.id.title);
        clubFragment=new ClubFragment();
        yuejianFragment=new YuejianFragment();
        l_club=(LinearLayout)view.findViewById(R.id.main_culb);
        l_train=(LinearLayout)view.findViewById(R.id.main_train);
        l_me=(LinearLayout)view.findViewById(R.id.main_me);
        l_yuejian=(LinearLayout)view.findViewById(R.id.main_yuejian);
        l_showpic=(LinearLayout)view.findViewById(R.id.main_showpic);
        //底部小图标
        yuejian_club_pic=(ImageView)view.findViewById(R.id.yuejian_club_pic);
        yuejian_train_pic=(ImageView)view.findViewById(R.id.yuejian_train_pic);
        yuejian_yuejian_pic=(ImageView)view.findViewById(R.id.yuejian_yuejian_pic);
        yuejian_showpic_pic=(ImageView)view.findViewById(R.id.yuejian_showpic_pic);
        yuejian_me_pic=(ImageView)view.findViewById(R.id.yuejian_me_pic);
        //底部文字
        yuejian_me_text=(TextView)view.findViewById(R.id.yuejian_me_text);
        yuejian_yuejian_text=(TextView)view.findViewById(R.id.yuejian_yuejian_text);
        yuejian_club_text=(TextView)view.findViewById(R.id.yuejian_club_text);
        yuejian_train_text=(TextView)view.findViewById(R.id.yuejian_train_text);
        yuejian_showpic_text=(TextView)view.findViewById(R.id.yuejian_showpic_text);



    }
   private boolean event(LinearLayout linearLayout,final  Fragment frag)
   {
       linearLayout.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               replace(frag);
           }
       });
       return true;
   }
    private  void replace(Fragment fragment)
    {
        transaction=fragmentManager.beginTransaction();
        transaction.replace(R.id.mainFrame,fragment);
        transaction.commit();
    }
    private void setTextColor()
    {
        yuejian_yuejian_text.setTextColor(Color.rgb(255,255,255));
        yuejian_club_text.setTextColor(Color.rgb(255,255,255));
        yuejian_me_text.setTextColor(Color.rgb(255,255,255));
        yuejian_showpic_text.setTextColor(Color.rgb(255,255,255));
        yuejian_train_text.setTextColor(Color.rgb(255,255,255));

    }
    private void setImage()
    {
        yuejian_club_pic.setImageResource(R.drawable.ic_club);
        yuejian_train_pic.setImageResource(R.drawable.ic_train_running_1);
        yuejian_yuejian_pic.setImageResource(R.drawable.ic_jianshen);
        yuejian_showpic_pic.setImageResource(R.drawable.ic_icon_pic);
        yuejian_me_pic.setImageResource(R.drawable.ic_me);
    }

}
